<?php

/**
 * 公共方法
 * @author Jinfeihu
 * 
 */
if (!function_exists('encryptionParam')) {

    /**
     * $param参数加密
     * 
     * */
    function encryptionUrl($param) {
        return encrypt($param);
    }

}
if (!function_exists('decryptParam')) {

    /**
     * $param参数解密
     * 
     * */
    function decryptUrl($param) {
        return decrypt($param);
    }

    if (!function_exists('getChaBetweenTwoDate')) {

        /**
         * 获取两个时间之间距离多少天
         * @param string $endTime 结束时间
         * @param string $beginTime 开始时间
         * @param string $explode 切割符
         * 
         */
        function getChaBetweenTwoDate(string $endTime, string $beginTime, string $explode = '-'): string {
            $Date_List_a1 = explode($explode, $endTime);
            $Date_List_a2 = explode($explode, $beginTime);
            $d1 = mktime(0, 0, 0, $Date_List_a1[1], $Date_List_a1[2], $Date_List_a1[0]);
            $d2 = mktime(0, 0, 0, $Date_List_a2[1], $Date_List_a2[2], $Date_List_a2[0]);
            $Days = round(($d1 - $d2) / 3600 / 24);
            return $Days;
        }

    }
    if (!function_exists('mbStrSplit')) {

        /**
         * 字符串通过长度转换数组
         * @param string $string 字符串
         *
         */
        function mbStrSplit($string, $len = 1): array {
            $start = 0;
            $strlen = mb_strlen($string);
            while ($strlen) {
                $array[] = mb_substr($string, $start, $len, "utf8");
                $string = mb_substr($string, $len, $strlen, "utf8");
                $strlen = mb_strlen($string);
            }
            return $array;
        }

    }
    if (!function_exists('generateTree')) {

        function generateTree($arr, $id = '0', $level = 0) {
            $list = array();
            foreach ($arr as $k => $v) {
                if ($v['pid'] == $id) {
                    $v['level'] = $level;
                    $v['son'] = generateTree($arr, $v['id'], $level + 1);
                    $list[] = $v;
                }
            }
            return $list;
        }

    }
}

